home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / estack.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.4 KB  |  133 lines

  1. /* Copyright (C) 1989, 1992, 1993, 1994, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: estack.h,v 1.2 2000/09/19 19:00:10 lpd Exp $ */
  20. /* Definitions for the execution stack */
  21.  
  22. #ifndef estack_INCLUDED
  23. #  define estack_INCLUDED
  24.  
  25. #include "iestack.h"
  26. #include "icstate.h"        /* for access to exec_stack */
  27.  
  28. /* There's only one exec stack right now.... */
  29. #define esfile (iexec_stack.current_file)
  30. #define esfile_clear_cache() estack_clear_cache(&iexec_stack)
  31. #define esfile_set_cache(pref) estack_set_cache(&iexec_stack, pref)
  32. #define esfile_check_cache() estack_check_cache(&iexec_stack)
  33.  
  34. /* Define the execution stack pointers for operators. */
  35. #define iexec_stack (i_ctx_p->exec_stack)
  36. #define e_stack (iexec_stack.stack)
  37.  
  38. #define esbot (e_stack.bot)
  39. #define esp (e_stack.p)
  40. #define estop (e_stack.top)
  41.  
  42. /*
  43.  * The execution stack is used for three purposes:
  44.  *
  45.  *      - Procedures being executed are held here.  They always have
  46.  * type = t_array, t_mixedarray, or t_shortarray, with a_executable set.
  47.  * More specifically, the e-stack holds the as yet unexecuted tail of the
  48.  * procedure.
  49.  *
  50.  *      - if, ifelse, etc. push arguments to be executed here.
  51.  * They may be any kind of object whatever.
  52.  *
  53.  *      - Control operators (filenameforall, for, repeat, loop, forall,
  54.  * pathforall, run, stopped, ...) mark the stack by pushing whatever state
  55.  * they need to save or keep track of and then an object with type = t_null,
  56.  * attrs = a_executable, size = es_xxx (see below), and value.opproc = a
  57.  * cleanup procedure that will get called whenever the execution stack is
  58.  * about to get cut back beyond this point because of an error, stop, exit,
  59.  * or quit.  (Executable null objects can't ever appear on the e-stack
  60.  * otherwise: if a control operator pushes one, it gets popped immediately.)
  61.  * The cleanup procedure is called with esp pointing just BELOW the mark,
  62.  * i.e., the mark has already been popped.
  63.  *
  64.  * The loop operators also push whatever state they need,
  65.  * followed by an operator object that handles continuing the loop.
  66.  *
  67.  * Note that there are many internal operators that need to be handled like
  68.  * looping operators -- for example, all the 'show' operators, since they
  69.  * may call out to BuildChar procedures.
  70.  */
  71.  
  72. /* Macro for marking the execution stack */
  73. #define make_mark_estack(ep, es_idx, proc)\
  74.   make_tasv(ep, t_null, a_executable, es_idx, opproc, proc)
  75. #define push_mark_estack(es_idx, proc)\
  76.   (++esp, make_mark_estack(esp, es_idx, proc))
  77. #define r_is_estack_mark(ep)\
  78.   r_has_type_attrs(ep, t_null, a_executable)
  79. #define estack_mark_index(ep) r_size(ep)
  80. #define set_estack_mark_index(ep, es_idx) r_set_size(ep, es_idx)
  81.  
  82. /* Macro for pushing an operator on the execution stack */
  83. /* to represent a continuation procedure */
  84. #define make_op_estack(ep, proc)\
  85.   make_oper(ep, 0, proc)
  86. #define push_op_estack(proc)\
  87.   (++esp, make_op_estack(esp, proc))
  88.  
  89. /* Macro to ensure enough room on the execution stack */
  90. #define check_estack(n)\
  91.   if ( esp > estop - (n) )\
  92.     { int es_code_ = ref_stack_extend(&e_stack, n);\
  93.       if ( es_code_ < 0 ) return es_code_;\
  94.     }
  95.  
  96. /* Macro to ensure enough entries on the execution stack */
  97. #define check_esp(n)\
  98.   if ( esp < esbot + ((n) - 1) )\
  99.     { e_stack.requested = (n); return_error(e_ExecStackUnderflow); }
  100.  
  101. /* Define the various kinds of execution stack marks. */
  102. #define es_other 0        /* internal use */
  103. #define es_show 1        /* show operators */
  104. #define es_for 2        /* iteration operators */
  105. #define es_stopped 3        /* stopped operator */
  106.  
  107. /*
  108.  * Pop a given number of elements off the execution stack,
  109.  * executing cleanup procedures as necessary.
  110.  */
  111. void pop_estack(P2(i_ctx_t *, uint));
  112.  
  113. /*
  114.  * The execution stack is implemented as a linked list of blocks;
  115.  * operators that can push or pop an unbounded number of values, or that
  116.  * access the entire e-stack, must take this into account.  These are:
  117.  *      exit  .stop  .instopped  countexecstack  execstack  currentfile
  118.  *      .execn
  119.  *      pop_estack(exit, stop, error recovery)
  120.  *      gs_show_find(all the show operators)
  121.  * In addition, for e-stack entries created by control operators, we must
  122.  * ensure that the mark and its data are never separated.  We do this
  123.  * by ensuring that when splitting the top block, at least N items
  124.  * are kept in the new top block above the bottommost retained mark,
  125.  * where N is the largest number of data items associated with a mark.
  126.  * Finally, in order to avoid specific checks for underflowing a block,
  127.  * we put a guard entry at the bottom of each block except the top one
  128.  * that contains a procedure that returns an internal "exec stack block
  129.  * underflow" error.
  130.  */
  131.  
  132. #endif /* estack_INCLUDED */
  133.